package com.haipumi.listeners;

import java.util.List;

import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.support.WebApplicationObjectSupport;

import com.haipumi.beans.haipumi_activity;
import com.haipumi.beans.haipumi_product;
import com.haipumi.biz.IBackActivityBiz;
import com.haipumi.biz.impl.BackActivityBizImpl;
import com.haipumi.utils.CommonData;

public class ActivityListener extends WebApplicationObjectSupport implements ApplicationListener<ContextRefreshedEvent> {
	
	
	@Autowired
	IBackActivityBiz backActivityBiz;
	
	
	private ServletContext servletContext;
    @Override
	protected void initServletContext(ServletContext servletContext) {
		this.servletContext=servletContext;
	}
    
    
    
    @Override
    public void onApplicationEvent(ContextRefreshedEvent ev) {
        //防止重复执行。
        if(ev.getApplicationContext().getParent() == null){
        	//访问数据库,得到所有的商品存到application中
    		
    		List<haipumi_activity> list=backActivityBiz.findAllActivity();
    		//如何取出application
    		
    		servletContext.setAttribute(CommonData.APPLICATIONACTIVITY, list);
        }
    }
 
}
